package com.yanqu.road.server.cmd.activity.commonteam;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonTeamProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.commonteam.CommonTeamActivity;
import com.yanqu.road.server.manager.activity.commonteam.CommonTeamMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_COMMON_TEAM_SEND_CHAT_MSG, desc = "通用组队-发送发送聊天")
public class CrossCommonTeamSendChatMsgCmd extends CrossUnionCommand {

    private long playerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        playerId = packet.getPlayerId();
        return true;
    }
    
    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CommonTeamProto.CommonTeamSendChatReqMsg reqMsg = CommonTeamProto.CommonTeamSendChatReqMsg.parseFrom(packet.getBytes());
        CommonTeamProto.CommonTeamSendChatRespMsg.Builder respMsg = CommonTeamProto.CommonTeamSendChatRespMsg.newBuilder();
        CommonTeamActivity activity = CommonTeamMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            CommonTeamMgr.getLogger().info("通用组队-发送聊天失败：活动不存在");
            return;
        }
        try {
            //发送聊天信息
            activity.sendTeamChatMsg(packet.getPlayerId(), reqMsg.getMsg());
            respMsg.setRet(0);
        } catch (BusinessException e) {
            CommonTeamMgr.getLogger().info("通用组队-发送聊天失败：{}", e.getCode());
        }
    }

    @Override
    public void sendData() {}
}
